#include "CFPSDetector.h"
#include <Windows.h>

CFPSDetector::CFPSDetector(void) 
{
	m_EndTime.QuadPart		= 0;
	m_StartTime.QuadPart	= 0;
	m_ClockSpeed.QuadPart	= 0;
	seconds					= 0;
	FPS						= 0;

	QueryPerformanceFrequency(&m_ClockSpeed);
}


CFPSDetector::~CFPSDetector(void)
{
}

//void FPSDetector::InitializeFPS(

float CFPSDetector::CalcSeconds(float frames = 1)
{
	//m_EndTime = m_StartTime;
	
	//QueryPerformanceCounter(&m_CurTime);

	//seconds = ((float)m_CurTime.QuadPart - (float)m_PrevTime.QuadPart) / (float)m_ClockSpeed.QuadPart;

	//Saves position for the next call to this function.
	//m_PrevTime = m_CurTime;
	return seconds;
}
/*
float FPSDetector::CalcFPS(float frames = 1)
{
	m_PrevTime = m_StartTime;
	
	QueryPerformanceCounter(&m_CurTime);

	FPS = (float)frames * ((float)m_ClockSpeed.QuadPart / ((float)m_CurTime.QuadPart - (float)m_PrevTime.QuadPart));

	//Saves position for the next call to this function.
	m_PrevTime = m_CurTime;
	return FPS;
}
*/

void CFPSDetector::Start()
{
	QueryPerformanceCounter(&m_StartTime);
}

void CFPSDetector::End()
{
	QueryPerformanceCounter(&m_EndTime);

	timedif = m_EndTime.QuadPart-m_StartTime.QuadPart;
	FPS = m_ClockSpeed.QuadPart / timedif; //ONE FRAME of time
}

float CFPSDetector::GetFPS()
{

	return FPS;
}